<?php

class User extends AppModel {

    public $label = 'Usuarios';
    public $plugin = 'Admin';
    public $belongsTo = array('Admin.Rol');
    public $validate = array(
        'name' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'El nombre es requerido'
            )
        ),
        'username' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'El nombre de usuario es requerido'
            )
        ),
        'email' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'El e-mail del usuario es requerido'
            ),
            'email' => array(
                'rule' => array('email'),
                'message' => 'El e-mail del usuario no es válido'
            )
        ),
        'rol_id' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'Por favor ingrese un rol válido'
            )
        )
    );

    public function beforeSave() {
        if (isset($this->data[$this->alias]['password'])) {
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        }
        return true;
    }

}